#pragma once

#include "GLCommon.h"
#include <QMenu>
#include <QOpenGLWidget>
class ScaleBar;
class ControlBar;
class GLWidget
	: public QOpenGLWidget
	, public GL_FUN
{
	Q_OBJECT
	using Super = QOpenGLWidget;

public:
	GLWidget(QWidget* parent = nullptr);
	~GLWidget();

	void startMove();
	void stopMove();

protected:
	void initializeGL() override;
	void resizeGL(int w, int h) override;
	void paintGL() override;
	void resizeEvent(QResizeEvent* event) override;
	void wheelEvent(QWheelEvent* event) override;
	void mousePressEvent(QMouseEvent* event) override;
	void mouseReleaseEvent(QMouseEvent* event) override;
	void mouseMoveEvent(QMouseEvent* event) override;
	void mouseDoubleClickEvent(QMouseEvent* event) override;
	void keyPressEvent(QKeyEvent* event) override;
	void keyReleaseEvent(QKeyEvent* event) override;

	void timerEvent(QTimerEvent* event) override;
protected slots:

	void doScaleAdd();
	void doScaleDec();

	void doControlCount(int v);

private:
	void calcFPS();
	void updateFPS(uint32_t fps);
	void showFPS();
	void showMenu(QPoint point, const QRect& windowRect);

private:
	uint32_t mTimer = 0;
	uint32_t mFPS	= 60;
#ifdef DEBUG_GL
	QOpenGLDebugLogger* mLogger = nullptr;
#endif
	const qreal cStep		= 0.1;
	ScaleBar*	mScaleBar	= nullptr;
	ControlBar* mControlBar = nullptr;

	QMenu* mMenu = nullptr;

	bool   mPressedBlank = false;
	QPoint mPressedWindowPos;
	QPoint mMovedWindowPos;
	bool   mMovedWhenBlankPress = false;
	bool   mCtrlPressed			= false;

	bool mControlMove = false;
};
